<?php

class Default_Bootstrap extends Zend_Application_Module_Bootstrap {
	
   function _initTranslations() {
		
				
		$bootstrap = $this->getApplication();
		$layout = $bootstrap->getResource('layout');
		$view = $layout->getView();
		
		$session = new Zend_Session_Namespace('Default');
		$config = Zend_Registry::get('config');
		$iso = isset($session->lang) ? $session->lang : $config['site']['defaultLang'];
		$locale = new Zend_Locale($iso);
		Zend_Registry::set('Zend_Locale', $locale);
		Zend_Registry::set('defaultLanguage', $config['site']['defaultLang']);
		
		$iso = $locale->getLanguage();
		$module = $this->getModuleName();
		
		$inipath = APPLICATION_PATH . '/languages/default_' . $iso . '.ini';
		if(!file_exists($inipath)) {
		   $inipath = APPLICATION_PATH . '/languages/default_'.$config['site']['defaultLang'].'.ini';
		   $iso = $config['site']['defaultLang'];
		}
		
		//$view->addBasePath(APPLICATION_PATH.'/modules/'.$module.'/views/'.$iso);
		
		$view->addBasePath(APPLICATION_PATH.'/modules/'.strtolower($module).'/views/');
		$view->addBasePath(APPLICATION_PATH.'/modules/'.strtolower($module).'/views/'.$iso);
		
      		$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
      		Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);      
      		$translate = new Zend_Translate('ini', $inipath, $iso);
		$locale = Zend_Registry::get('Zend_Locale');
		if (!$translate->isAvailable($locale->getLanguage())) {
		    // not available languages are rerouted to another language
		    $translate->setLocale(Zend_Registry::get('defaultLanguage'));
		}
		$view->translate = $translate;
		$view->session = $session;
	}
	
	
}